Classname GeneralFunctions
Contains the basic functions for reading and saving pages
Note: this class will be used by the implementation classes AND the backend of the feindura-CMS.
static array | $adminConfig | Contains the administrator-settings config array |
static array | $categoryConfig | Contains the category-settings config array |
static array | $userConfig | Contains the user config array |
static array | $websiteConfig | Contains the website-settings config array |
static array | $pagesMetaData | Contains the pagesMetaData array |
static array | $storedPages | Stores page-content array's in this property if a page is loaded |
static array | $FeinduraCLass | Keeps an instance of the Feindura class to be used in the GeneralFunctions::replaceSnippets() method. |
static bool | $isAdmin | Stores the result of GeneralFunctions::isAdmin(), to speed it up. |
Contains the administrator-settings config array
Contains the category-settings config array
Contains the pagesMetaData array
This array contains all pages IDs and their category ID, as well as the localized titles
Example array:
Show Example
Stores page-content array's in this property if a page is loaded
If a page is loaded (included) it's page-content array will be stored in the this array.
If the page is later needed again it's page-content will be fetched from this property.
It should speed up the page loading process.
Keeps an instance of the Feindura class to be used in the GeneralFunctions::replaceSnippets() method.
Type init
The real constructor of the static class, gets the settings.
Used Global Variables
string | $standardLang |
the standard country code to return when no language code was get Default "en-GB" |
bool | $simple |
if TRUE it only returns a string with a language code, if FALSE it returns an array with the language Default true |
Name getBrowserLanguages()
Checks for the browser language an create an array with all languages an q-values:
Array ( [de-de] => 1 [de] => 0.8 [en-us] => 0.5 [en] => 0.3 )
If no match to the browser language is found it uses the $standardLang parameter for loading a languageFile or returning the country code.
static array loadLanguageFile ( |
[string|false = false], [string = '%lang%.php'], [string|false = false], [bool = 'en']) |
string|false | $langPath |
(optional) a absolut path to look for a language file which fit the $filename parameter or FALSE to use the "feindura-cms/library/languages" folder Default false |
string | $filename |
(optional) the structure of the filename, which should be loaded. the "%lang%" will be replaced with the country code like "%lang%.backend.php" -> "en.backend.php" Default '%lang%.php' |
string|false | &$currentLangCode |
(optional) (Note: this variable will also be changed outside of this method) a variable with the current language code, if this is set it will be first try to load this language file, when it couldn't find any language file which fits the browsers language code. Default false |
bool | $standardLang |
(optional) a standard language for use if no match was found Default 'en' |
Name loadLanguageFile()
Loads a language file from a folder. The $currentLangCode parameter can contain a language code used to try to load a language file, if empty it uses the browsers language codes.
If no match to the browser language is found it uses the $standardLang parameter for loading a languageFile.
Used Constants
Name setVisitorTimzone()
Try to get the visitors timezone by using javascript. It will create a redirect along with the visitors local timezone, which then get catched in the next run of this function and stored in the $_SESSION['feinduraSession']['timezone'] variable.
Name isAdmin()
Check if the current user is an admin. If no users exist everyone is an admin.
Used Global Variables
string | $permission |
the array key of the permission to check |
string|int | $data |
(optional) some data which is required so some checks (like category or page IDs) Default false |
int|bool | $userId |
(optional) a user id which should be used as the current user Default false |
Name hasPermission()
Check if the user has the permissions of the given $permission parameter.
string|array | $key |
the key of the new parameter to add, if array, the value parameter must also be an array |
string|array|false | $value |
(optional) the value of the new parameter to add Default '' |
Name addParameterToUrl()
Check if the current $_SERVER['REQUEST_URI'] variable end with ? or & and ads the $parameterString on the end.
string | $uri |
the URI to change |
Name URI2Path()
Removes the URIEXTENSION from a given URI.
string | $path |
the path to change |
Name Path2URI()
Adds the URIEXTENSION to a given path.
string | $dir |
the path to get the dirname from |
Name getDirname()
Returns the dirname of a $dir parameter, by checking whether the last part of the path is a filename or a dir.
int | $pageContent |
a $pageContent array which should be add to the $storedPages property |
int | $id |
the ID of a page which should be removed from the $storedPages property |
int | $page |
a page ID from which to get the category ID |
Name getPageCategory()
Return the category ID of a page.
int | $categoryId |
a category ID |
Name getParentPages()
Returns an array with the parent pages of given subcategory. If the given category ID is not a sub category of any page, it will return an empty array.
static string getLocalized ( |
array , string , [ = false], [ = false], bool|string ) |
array | $localizedArray |
an array with an ['localized'] array in the form of: array('de' => .. , 'en' => .. ) |
string | $value |
the name of the value, which should be returned localized |
bool|string | $forceOrUseLanguage |
if TRUE the language will be forced to be loaded, even if it does not exist, if string it will be try this as the testing language code, instead of the $_SESSION['feinduraSession']['websiteLanguage'] var Default false |
$languageCode |
Default false | |
$forceLanguage |
|
Name getLocalized()
Gets the localized version of given $value parameter, which matches the $_SESSION['feinduraSession']['websiteLanguage'] variable. If no matching localized version of this value exists, it returns the one matching the $websiteConfig['multiLanguageWebsite']['mainLanguage'] variable.
array | $pageData |
the $pageContent or $pageMetaData array of a page |
array|string | $tags |
an array or string with tags to compare |
Name compareTags()
Compares the given tags with the tags in the given $pageData array.
If the given $pageData array has one or more tags from the $tags parameter, it returns TRUE otherwise it FALSE.
Note: the tags will be compared case insensitive.
int|array | $page |
a page ID or a $pageContent array (will then returned immediately) |
int | $category |
(optional) a category ID, if FALSE it will try to load this page from the non-category Default false |
bool | $readPrevious |
(optional) if TRUE it will read the previous state of the page instead of the current page Default false |
Name readPage()
Loads the $pageContent array of a page.
Checks first whether the given page ID was already loaded and is contained in the $storedPages property. If not the GeneralFunctions::readPage() public static function is called to include the $pagecontent array of the page and store it in the $storedPages property.
Example of the returned $pageContent array:
Show Example
array|int | $page |
an page id, or the $pageContent array of a page |
int|false | $catgory |
(optional) the pages category id, or false to let it determine automatically Default false |
bool | $savePagesMetaData |
(optional) it FALSE it won't save the $pagesMetaData array Default true |
Name deletePage()
Deletes a page and all depencies of it.
array | $pageContent |
the $pageContent array of the page to save |
bool | $readPrevious |
(optional) if TRUE it will save the given $pageContent as a previous state of the page Default false |
bool | $savePagesMetaData |
(optional) it FALSE it won't save the $pagesMetaData array Default true |
$savePrevious |
|
Name savePage()
Save a page to it's flatfile.
Example of the saved $pageContent array:
Show Example
Used Constants
Name savePagesMetaData()
Save all pages meta data in an array, to faster access them. It also reloads them as properties in the GeneralFunctions and StatisticsFunctions classes.
Example of the $pagesMetaData array:
Show Example
bool|int|array | $category |
(optional) a category ID, or an array with category IDs. TRUE to load all categories (including the non-category) or FALSE to load only the non-category pages Default false |
Name getPagesMetaDataOfCategory()
Filters the GeneralFunctions::$pagesMetaData array and retruns only the pages which have a specific category.
bool|int|array | $category |
(optional) a category ID, or an array with category IDs. TRUE to load all categories (including the non-category) or FALSE to load only the non-category pages Default true |
Name loadPages()
Loads the $pageContent arrays from pages in a specific category(ies) or all categories.
Loads all $pageContent arrays of a given category, by going through the $pagesMetaData array. It check first whether the current $pageContent array was not already loaded and is contained in the $storedPages property. If not the GeneralFunctions::readPage() public static function is called to include the $pagecontent array of the page and store it in the $storedPages property.
Note: after loading all $pageContent arrays of a category, the array with the containing $pageContent arrays will be sorted.
Example of the returned $pageContent arrays:
Show Example
bool|int|array | $category |
(optional) a category ID, or an array with category IDs. TRUE to load all categories (including the non-category) or FALSE to load only the non-category pages Default true |
Name loadPagesStatistics()
Loads the $pageStatistics arrays from pages in a specific category(ies) or all categories.
Loads all $pageStatistics arrays of a given category, by going through the $pagesMetaData property and load the right "[pageID].statistics.php".
Note: after loading all $pageStatistics arrays of a category, the array with the containing $pageStatistics arrays will be sorted.
Example of the returned $pageStatistics arrays:
Show Example
int|array|bool | $ids |
the category or page ID(s), can be a number or an array with numbers, if TRUE then it check all categories |
Name isPublicCategory()
Checks whether the given category(ies) are public and returns the ID or an array with IDs of the public ones.
Note: This method can either return 0 for the non-category or false. Use "… === false" to check if a category is not public.
int|array | $page |
the variable to check |
Name isPageContentArray()
Checks the given $page parameter is a valid $pageContent array.
int | $intDate |
intDate integer optional Default null |
bool | $onlyDate |
onlyDate whether or not the datetime attribute should contain only the date or add the time also Default true |
Name getDateTimeValue()
formats the date passed into format required by 'datetime' attribute of <time> tag. If no intDate supplied, uses current date.
int | $timeStamp |
a UNIX-Timestamp |
string|false | $format |
(optional) the format type can be "DMY" to format into: "DD.MM.YYYY", "YMD" to format into: "YYYYY-MM-DD" or "MDY" to format into: "MM/DD/YYYYY", if FALSE it uses the format set in the administrator-settings config Default 'DMY' |
string | $dateSize |
(optional) can be 'D', 'DM' or 'DMY', to display only days, days and month or a full day |
Name formatDate()
Converst a given timestamp into the a specific format type.
static string|int dateDayBeforeAfter ( |
int , [array|false = false], [string = 'DMY']) |
int | $timestamp |
the timestamp to check |
array|false | $langFile |
(optional) the languageFile which contains the ['DATE_TEXT_YESTERDAY'], ['DATE_TEXT_TODAY'] and ['DATE_TEXT_TOMORROW'] texts, if FALSE it loads the backend language-file Default false |
string | $dateSize |
(optional) can be 'D', 'DM' or 'DMY', to display only days, days and month or a full day Default 'DMY' |
Name dateDayBeforeAfter()
Replaces the given $date parameter with "yesterday", "today" or "tomorrow" if it is one day before or the same day or one day after today. It will also wrap the date(s) in a <time> tag.
Used Global Variables
static string|false showPageDate ( |
array , [bool = true], [array|false = false]) |
array | $pageContent |
the $pageContent array of a page |
bool | $useText |
(optional) is TRUE it uses the names Today,Tomorrow, Yesterday these dates, if FALSE it always uses just dates. Default true |
array|false | $langFile |
(optional) a language file to use, if FALSE it uses the global $langFile variable. Default false |
Name showPageDate()
Returns either a single page date or a date range formated, ready to display in an HTML page.
string | $countryCode |
a country code like "en" |
bool | $backend |
(optional) if true it removes the feindura basePath Default true |
Name getFlagSrc()
Returns the right flag from the library/images/icons/flags folder. If no flag with the given $countryCode parameter exists, it returns a generic flag (library/images/icons/flags/none.png).
static string createHref ( |
array , [string|false = false], [bool|string = false], [bool = false]) |
array | $pageContent |
the $pageContent array of a page |
string|false | $sessionId |
(optional) the session ID string in the following format: "sessionName=sessionId" Default false |
bool|string | $languageCode |
(optional) a language code to use when generating the link, if FALSE it uses the $_SESSION['feinduraSession']['websiteLanguage'] variable Default false |
bool | $fullUrl |
(optional) if TRUE it add also the URL to the href path Default false |
Name createHref()
Creates a href-attribute from the given $pageContent parameter, if the sessionId parameter is given it adds them on the end of the href string.
array | $pageContentArrays |
the $pageContent array of a page |
string|false | $sortBy |
(optional) the name of the sort function to use, if FALSE it uses automatically the right sort-public static function for the category Default false |
Name sortPages()
Sort an array with $pageContent arrays by a given sort function. The following sort functions are available by default and can be used for the $sortBy parameter:
int | $page |
a page ID |
int | $category |
a category ID |
Name createBreadCrumbsArray()
Creates an array with $pageContent arrays in the order of the navigation.
string | $folder |
the path of the plugin folder to look for stylesheet files |
Name addStylesheetsInBody()
Goes through a folder recursive and gets the css files. It then tries to add these as <link..> tags inside the <head> tag, using javascript. If no javascript is activated it will just place the <link...> tags to the current position.
string | $content |
a string with pluginPlaceholders |
Name cleanPluginPlaceholders()
Removes the src attribute and adds back the draggable=true attribute.
string | $string |
the string to clear |
string | $replaceString |
(optional) the string which replaces all special chars found Default '' |
Name cleanSpecialChars()
Removes all special chars from a string.
string | $title |
the title string to shorten |
int | $length |
the number of letters the string should have after |
$string |
|
Name shortenString()
Shortens a string to its letter number (conciders htmlentities as multiple characters).
string | $string |
the data to check against htmlLawed |
array | $config |
(optional) if given it will be used as the config array fpr the htmLawed function Default false |
Name htmLawed()
Uses the htmLawed function but decodes first UTF-8 and after encodes again.
string | $path |
an absolute or relative path |
Name getRealPath()
Try to get the real path from a given absolute or relative path. If the path contains a filename it will ony return the folders in the path (strapping the filename).
Used Constants
string | $folder |
an absolute or relative path of an folder to read |
Name readFolder()
Reads a folder and return it's subfolders and files.
Example of the returned array:
Show Example
Used Constants
string | $folder |
an absolute or relative path of an folder to read |
Name readFolderRecursive()
Reads a folder recursive and return it's subfolders and files, opens then also the subfolders and read them, etc.
Example of the returned array:
Show Example
Used Constants
string | $folder |
the absolute path of an folder to check |
Name folderIsEmpty()
Check if a folder is empty.
Used Constants
string | $dir |
the absolute path to the directory which will be deleted |
Name deleteFolder()
Deletes a directory and all files in it.
string | $folder |
the absolute path of the folder to look for stylesheet files |
bool | $backend |
if TRUE is substract the $adminConfig['basePath'] from the stylesheet link Default false |
bool | $returnHrefOnly |
if TRUE it will return an array with the paths of the style files |
Name createStyleTags()
Goes through a folder recursive and creates a HTML <link> tag for every stylesheet-file found.
Used Global Variables
$str |
|
Name smartStripslashes()
Uses stripslashes depending on "magic_quotes_gpc" and "magic_quotes_sybase"
string | $json |
a json encoded string |
Name jsonDecode()
Decodes a JSON object in php, without using json_decode() so its PHP 5.1 compatible.
string replaceLinks ( |
string $pageContentString, [bool|string $sessionId = false], [bool|string $language = false], [bool $fullUrl = false]) |
string | $pageContentString |
the page content string, to replace all feindura links, with real hrefs |
bool|string | $sessionId |
(optional) the session id which should be transported to the GeneralFunctions::createHref() method Default false |
bool|string | $language |
(optional) the language code id which should be transported to the GeneralFunctions::createHref() method Default false |
bool | $fullUrl |
(optional) if TRUE it replaces the links with full URLs (containing the domain) Default false |
Name replaceLinks()
Replaces all feindura links (e.g. "?feinduraPageID=3") inside the given $pageContentString parameter, with real href links.
string replaceSnippets ( |
string $pageContentString, int $pageId, [bool $removeSnippets = false]) |
string | $pageContentString |
the page content string, to replace all feindura links, with real hrefs |
int | $pageId |
the current page ID to load the right plugins. |
bool | $removeSnippets |
(optional) will only remove the snippets placeholder from the $pageContentString Default false |
Name replaceSnippets()
Replaces all feindura code snippets (e.g. "<img class="feinduraSnippet"...>) inside the given $pageContentString parameter, with either a code snippet or a plugin.